<?php

namespace App\Http\Controllers;
use App\Models\User;
use Illuminate\Http\Request;
class UserController extends Controller
{
    public function index(){
        $user = User::all();
//        return view('login',['user'=>$user]);
//        return view('login',compact('user'));
        return json_encode($user);
    }
    public function login(Request $request){
        $user = User::where('name',$request->name)->first();
        if($user){
            if($user->password == $request->password){
                return view('index',['user'=>$user]);
            }else{
                return view('login',['user'=>$user]);
            }
        }else{
            return view();
        }
    }
}
